#encoding: utf-8
require 'api_helpers'
module GrapeAPI
  module V1
    class MobileInterface < Grape::API
      version "v1"
      helpers GrapeAPI::APIHelpers
      #set method
      before do
       authenticate!
      end
      
      #===终端用户信息修改===#
      resource :userinfo do
        #===== 应用 get
        post do
          _user_id = params["user_id"]
          if current_user.id.to_s == _user_id
            if current_user.public_confirm
              response_format!(current_user.public_confirm)
            else
              server_error!
            end
          else
            unknow_user!
          end
        end
        
        put do
          _user_id = params["user_id"]
          if current_user.id.to_s == _user_id
            begin
              _info = params["user_info"]
              current_user.public_confirm.update_attributes(_info.to_h) if _info.size > 0
              response_format!
            rescue
              attribute_error!
            end
          else
            unknow_user!
          end
        end
      end
      
      #修改密码
      resource :chengeUserPwd do
        post do
          token_code = params["token"]
          identity_url = params["identity_url"]
          user_name = params["user_name"]
          user = User.where(:username => user_name).first

          unless user.nil?
            user.update
          end
          {:status => 200, :msg => "get ok"}
        end
      end
    end
  end
end